package statistics;

import java.util.ArrayList;
import java.util.List;

import base.DreamScript;
import base.DreamUtility;

public class LevelGoalHandler extends DreamUtility {
	private List<LevelGoal> finishedGoals = new ArrayList<LevelGoal>();

	public LevelGoalHandler(DreamScript cs) {
		super(cs);
	}

	public boolean hasReachedTargetLevel(LevelGoal goal) throws InterruptedException {
		return cs.theTabs.Statistics.getStatBottom(goal.getSkill()) == goal.getTargetLevel();
	}

	public boolean hasFinishedGoal(LevelGoal goal) throws InterruptedException {
		return finishedGoals.contains(goal);
	}

	public void doGoalAction(LevelGoal goal) throws InterruptedException {
		if (hasReachedTargetLevel(goal) && !hasFinishedGoal(goal)) {
			if (goal.isShutdown()) {
				cs.getLogoutHandler().logout(true);
			} else {
				cs.getCombatUtils().switchAttackMode(goal.getModeSwitch(), cs.getTabHandler());
			}

			finished(goal);
		}
	}

	public void finished(LevelGoal goal) {
		finishedGoals.add(goal);
	}
}
